﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;

namespace MetaCollection.ContentService.WebDav
{
	/// <summary>
	/// Implements a name comparison test set that ignores case of item names.
	/// </summary>
	public class PropertyNameComparer : IEqualityComparer<XName>
	{
		#region IEqualityComparer<XName> Members

		/// <summary>
		/// Determines whether the specified objects are equal.
		/// </summary>
		/// <param name="x">The first object of type <paramref name="T"/> to compare.</param>
		/// <param name="y">The second object of type <paramref name="T"/> to compare.</param>
		/// <returns>
		/// true if the specified objects are equal; otherwise, false.
		/// </returns>
		public bool Equals(XName x, XName y)
		{
			if (x != null && y != null)
				return x.LocalName.Equals(y.LocalName, StringComparison.OrdinalIgnoreCase) && x.NamespaceName.Equals(y.NamespaceName, StringComparison.OrdinalIgnoreCase);
			else
				return x == null && y == null;
		}

		/// <summary>
		/// Returns a hash code for the specified object.
		/// </summary>
		/// <param name="obj">The <see cref="T:System.Object"/> for which a hash code is to be returned.</param>
		/// <returns>A hash code for the specified object.</returns>
		/// <exception cref="T:System.ArgumentNullException">
		/// The type of <paramref name="obj"/> is a reference type and <paramref name="obj"/> is null.
		/// </exception>
		public int GetHashCode(XName obj)
		{
			return obj.GetHashCode();
		}

		#endregion
	}
}
